<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>03-axios的介绍与页面配置</title>
    <!-- 这样即可引入axios -->
    <script src="https://cdn.bootcdn.net/ajax/libs/axios/1.3.4/axios.js"></script>
</head>
<body>
    <button>GET</button>
    <button>POST</button>
    <button>PUT</button>
    <button>DELETE</button>

    <script>
        let btns = document.querySelectorAll('button');
        
        // axios也提供了下面这种直接 .方法名 的去调用的方式
        btns[0].onclick = ()=>{
            axios.get('http://localhost:10086/demo/demoGet')
            .then(res => {
                console.log(res)
            })
            .catch(err => {
                console.error(err); 
            })
        }

        btns[1].onclick = ()=>{
            axios.post('http://localhost:10086/demo/demoPost',{name:'123'})
            .then(res => {
                console.log(res)
            })
            .catch(err => {
                console.error(err); 
            })
        }

        btns[2].onclick = ()=>{
            axios.put('http://localhost:10086/demo/demoPut',{name:'234'})
            .then(res => {
                console.log(res)
            })
            .catch(err => {
                console.error(err); 
            })
        }

        btns[3].onclick = ()=>{
            axios.delete('http://localhost:10086/demo/demoDelete',{name:'333'})
            .then(res => {
                console.log(res)
            })
            .catch(err => {
                console.error(err); 
            })
        }
    </script>
</body>
</html>